package com.tanger.common.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

/**
 * 加载配置文件基类
 * @author Hchenbin
 * @Date 2022/08/01
 *
 */
public class LoadConfig {
	
	protected static Properties p = new Properties();

	protected static void init(String propertyFileName) {
		InputStream in = null;
		try {
			in = LoadConfig.class.getResourceAsStream(propertyFileName);
			if (in != null)
				p.load(new InputStreamReader(in,"utf-8"));
		} catch (IOException e) {
			System.out.println("load " + propertyFileName + " into Contants error");
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					System.out.println("载入系统配置文件时出错，文件路径：" + propertyFileName);
				}
			}
		}
	}

	protected static String getProperty(String key, String defaultValue) {
		return p.getProperty(key, defaultValue);
	}
	
	protected static String getProperty(String key, String defaultValue, String configFile) {
		init(configFile);
		return p.getProperty(key, defaultValue);
	}
}
